package cn.tedu.javagame.Plane;

import cn.tedu.javagame.star.StarFrame;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class Enemy extends FlyObject{
    //属性
    int fire,life;
//    static Image img;
//    static Image[] imgs;
    //静态代码块


    public Enemy(){
        super();
        imgs = new Image[6];
        img = new ImageIcon("plane/flys.png").getImage();
        for(int i=0;i<imgs.length;i++){
            imgs[i] = new ImageIcon("plane/flys"+i+".png").getImage();
        }
        this.x = (int)(Math.random()*(ShootFrame.WIDTH-img.getWidth(null)));
        this.y = -img.getHeight(null);
        this.fire = 1;
        this.life = 100;

    }
    //方法
    @Override
    public void move(){
        this.y += this.speed;
    }
//    int index = -1;
//    public void step(){
//        if(index==Integer.MAX_VALUE){index=0;}
//        int i = index++/5%imgs.length;
//        img = imgs[i];
////        System.out.println(i);
//    }
    //发射子弹
    public List<EnemyBullet> shoot(){
        List<EnemyBullet> enemyBulletsList = new ArrayList<>();
        int x = this.x + img.getWidth(null)/2;
        int y = this.y;
        EnemyBullet enemyBullets = new EnemyBullet(x,y);
        enemyBulletsList.add(enemyBullets);
        return  enemyBulletsList;
    }
}